/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * <p>Project: sboot2021 - App
 * <p>Powered by webrx On 2021-07-28 15:49:40
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
@SpringBootApplication
public class App implements ApplicationRunner {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    /**
     * java -jar .\01demo-1.0.jar hello springboot --p1=500 --p2=1000
     * 4
     * hello
     * springboot
     * [p1, p2]
     * [500]
     * [hello, springboot]
     * 500
     * 1000
     * @param args
     * @throws Exception
     */

    @Override
    public void run(ApplicationArguments args) throws Exception {
        String[] ps = args.getSourceArgs();
        System.out.println(ps.length);//4
        System.out.println(ps[0]);//hello
        System.out.println(ps[1]);//springboot

        System.out.println(args.getOptionNames());//[p1, p2]
        System.out.println(args.getOptionValues("p1"));//[500]
        System.out.println(args.getNonOptionArgs());//[hello, springboot]
        //输出500 1000
        args.getOptionNames().forEach(e->System.out.println(args.getOptionValues(e).get(0)));
    }
}
